/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.commons.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import br.ufmg.dees.insane.commons.command.Command;

/**
* This class is a implementation of the interface ActionListener.
* It is used to deal with events from Console's Prompt
* @author Fonseca,Flavio & Pitangueira, Roque
* @since January 2004
* @see java.awt.event.ActionListener
* @see gui.Console
*/
public abstract class ConsoleHandler extends KeyAdapter implements ActionListener {
	
	protected static int COMMAND_MODE = 1;
	protected static int DATA_MODE = 2;
	
	protected Interface parent;
	protected String str;
	protected Command cmd;
	protected Command cmd2;
	protected int counter;
	protected int mode;
	
//*****************************************************************************
	
	/** Constructor Method.
	* @param parent The parent Interface.
	*/
	public ConsoleHandler() {}
	
	/** Constructor Method.
	* @param parent The parent Interface.
	*/
	public ConsoleHandler(Interface parent) {
		this.parent = (Interface)parent;
		this.setToCommandMode();
	}
	
//*****************************************************************************
	
	/** Method which executes the desired action to each valid command.*/
	public abstract void actionPerformed(ActionEvent evt);
	
//*****************************************************************************
	
	/** Method to treat events from a key.
	*@param evt The key event to be treated;
	*/
	public abstract void keyReleased(KeyEvent evt);
	
//*****************************************************************************
	
	/** Sets this ConsoleHandler to data mode.*/
	public void setToDataMode() {
		mode = DATA_MODE;
	}
	
//*****************************************************************************
	
	/** Sets this ConsoleHandler to command mode.*/
	public void setToCommandMode() {
		mode = COMMAND_MODE;
	}
	
//*****************************************************************************
	
	/** Sets the keyboard command (cmd2).
	* @param command The kayboard command to be set.
	*/
	public void setKeybCommand(Command command) {
		cmd2 = command;
	}
	
//*****************************************************************************
	
	/** Returns the keyboard command (cmd2).
	* @return The kayboard command (cmd2).
	*/
	public Command getKeybCommand() {
		return cmd2;
	}
	
//*****************************************************************************
}
